#!/bin/bash

if [[ $# -eq 1 ]];then
    if [[ "$1" == "clean" ]]; then
        if [ -d "build" ]; then
            cd build || exit
            make clean
        fi
    elif [[ "$1" == "clean_all" ]]; then
        if [ -d "build" ]; then
            rm -rf build
        fi
    elif [[ "$1" == "build" ]]; then
        if [ ! -d "build" ]; then
            mkdir build
        fi
        cd build || exit
        cmake ..
        make
    elif [[ "$1" == "rebuild" ]]; then
        if [ ! -d "build" ]; then
            mkdir build
        fi
        cd build || exit
        cmake ..
        make
    elif [[ "$1" == "run" ]]; then
        if [ -d "build/bin" ]; then
            cd build/bin || exit
            ./mini_web_service
        else
            echo -e "请编译工程后再来运行"
        fi
    elif [[ "$1" == "config" ]]; then
        if [ -d "scripts" ]; then
            cd scripts || exit
            ./menuconfig
        else
            echo -e "无法进行工程配置"
        fi
    elif [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
        echo -e "${0##*/} build     : 编译工程"
        echo -e "${0##*/} rebuild   : 重新编译工程"
        echo -e "${0##*/} run       : 运行工程"
        echo -e "${0##*/} clean     : 清除工程"
        echo -e "${0##*/} clean_all : 删除生产工程编译文件"
    else
        echo -e "输入有误,请输入 ${0##*/} --help 查看帮助"
    fi
else
    echo -e "输入有误,请输入 ${0##*/} --help 查看帮助"
fi
